import requests

#from testRequest.Wework.base import Base
from weixin_app.base import Base


class WeworkAdress(Base):

    def get_user(self,userid:str):
        #userid = 'zhangsan'
        params = {
            "userid":userid
        }
        r=self.send("GET","https://qyapi.weixin.qq.com/cgi-bin/user/get",params=params)
        #print(r.json())
        return r.json()
        #assert r.json()['errmsg']== 'ok'

    def add_user(self,userid:str,name:str,mobile:str,department:list):
        """

        :param userid:
        :param name:
        :param mobile:
        :param department:
        :return:
        """

        data = {
            "userid": userid,
            "name": name,
            "mobile": mobile,
            "department": department
        }
        r=self.send("POST","https://qyapi.weixin.qq.com/cgi-bin/user/create",json=data)
        return r.json()

    def update_user(self,userid:str,name:str):
        data = {
            "userid": userid,
            "name": name
        }
        r=self.send("POST","https://qyapi.weixin.qq.com/cgi-bin/user/update",json=data)
        return r.json()

    def del_user(self,userid:str):
        #userid = userid
        params = {

            "userid":userid
        }
        r=self.send("GET","https://qyapi.weixin.qq.com/cgi-bin/user/delete",params=params)
        return r.json()
